﻿Imports System.Data.SqlClient

Public Class 支出查询
    Private Sub 支出查询_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        loadZcjlData()
    End Sub

    Function loadZcjlData()
        ' SQL 查询，列名替换为中文
        Dim sql As String = "
SELECT 
    ID AS [支出账单编号],
    ZCSJ AS [支出时间],
    ZCFS AS [支出方式ID],
    ZCFSMC AS [支出方式名称],
    MEMO AS [备注],
    DD AS [地点],
    SKF AS [收款人],
    ZCJE AS [支出金额]
FROM ZCJLK
ORDER BY ZCSJ DESC
"


        Try
            Dim dt As New DataTable()

            Using conn As New SqlConnection(DbConnectionHelper.GetConnectString())
                DbConnectionHelper.OpenConnection(conn)

                Using da As New SqlDataAdapter(sql, conn)
                    da.Fill(dt)
                End Using

                DbConnectionHelper.CloseConnection(conn)
            End Using

            ' 绑定 DataGridView
            DataGridView1.DataSource = dt

            ' 隐藏 ID 列
            If DataGridView1.Columns.Contains("支出账单编号") Then
                DataGridView1.Columns("支出账单编号").Visible = False
            End If

            ' 让列宽撑满整个 DataGridView
            DataGridView1.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill

            ' 可选：设置列比例（权重）
            ' 比如支出时间和支出方式占比大一些
            'If DataGridView1.Columns.Contains("支出时间") Then
            '    DataGridView1.Columns("支出时间").FillWeight = 15
            'End If
            'If DataGridView1.Columns.Contains("支出方式名称") Then
            '    DataGridView1.Columns("支出方式名称").FillWeight = 15
            'End If
            'If DataGridView1.Columns.Contains("备注") Then
            '    DataGridView1.Columns("备注").FillWeight = 20
            'End If
            'If DataGridView1.Columns.Contains("地点") Then
            '    DataGridView1.Columns("地点").FillWeight = 15
            'End If
            'If DataGridView1.Columns.Contains("收款人") Then
            '    DataGridView1.Columns("收款人").FillWeight = 10
            'End If
            'If DataGridView1.Columns.Contains("支出金额") Then
            '    DataGridView1.Columns("支出金额").FillWeight = 15
            'End If

        Catch ex As Exception
            MessageBox.Show("加载支出记录失败：" & ex.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error)
        End Try
    End Function

    Private Sub 查询btn_Click(sender As Object, e As EventArgs) Handles 查询btn.Click

    End Sub
End Class